<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__MANAGE__lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__MANAGE__lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__MANAGE__css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    {volist name="data" id="vo"}
    <?php if($vo['type'] == '1'){ ?>
    <div class="layui-form-item">
        <label class="layui-form-label">{$vo.cnname}</label>
        <div class="layui-input-block">
            <input type="text" placeholder="{if $vo['enname']=='redirect'}请输入完整网站，http:// 开头{/if}" name="{$vo.enname}" value="{$vo.value}" class="layui-input">
        </div>
    </div>
    <?php } ?>
    <?php if($vo['type'] == '2'){ ?>
    <div class="layui-form-item">
        <label class="layui-form-label">{$vo.cnname}</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" name="{$vo.enname}" class="layui-textarea">{$vo.value}</textarea>
        </div>
    </div>
    <?php } ?>
    <?php if($vo['type'] == '3'){ ?>

    <div class="layui-form-item">
        <label class="layui-form-label">{$vo.cnname}</label>
        <div class="layui-input-block">
            <?php $lizhi=explode(",",$vo['kxvalue']);
									foreach($lizhi as $k=>$v)
            {
            ?>
            <input type="radio" value="{$v}"  <?php if($v==$vo['value']){ echo 'checked' ;}?> name="{$vo.enname}" title="{$v}">
            <?php	}	?>
        </div>
    </div>

    <?php } ?>
    <?php if($vo['type'] == '4'){ ?>

    <div class="layui-form-item">
        <label class="layui-form-label">{$vo.cnname}</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn test">上传图片</button>
                <input type="hidden" name="{$vo.enname}" value="" class="lizhili_hidden">
                <div class="layui-upload-list">
                    <img class="layui-upload-img lizhili" src="{$vo.value|default=''}" style="width: 200px">
                </div>
            </div>
        </div>
    </div>
    <?php } ?>
    {/volist}



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="__MANAGE__lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="__MANAGE__js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['upload','form'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

            var uploadInst = upload.render({
                elem: '.test'
                ,url: 'update?lizhili=123456'
                ,accept:'images'
                ,before: function(obj){
                    layer.msg('上传中', {icon: 16, time: 0});
                    let that=this
                    obj.preview((index, file, result)=>{
                        that.item.parent().find('.lizhili').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    this.item.parent().find('.lizhili_hidden').val(res.data); //图片链接（base64）
                    return layer.msg('上传成功');
                }
            });

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.post("api",
                {
                    data:data.field,
                    'type':'show_edit',
                },
                function(res,status){
                    if(res.code==0){
                        //  var iframeIndex = parent.layer.getFrameIndex(window.name);
                        // parent.layer.close(iframeIndex);
                        layer.msg(res.msg, {icon: 1});
                        setTimeout(function(){
                            window.parent.location.reload();//修改成功后刷新父界面
                        }, 300);
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                });

            return false;
        });

    });
</script>
</body>
</html>